//
//  MyView.m
//  NavigationDemo
//
//  Created by 商广硕 on 2022/7/16.
//

#import "MyView.h"

@implementation MyView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
+ (instancetype)myView {
    //初始化
    MyView* view = [[MyView alloc] init];
    if ([self isNotchScreen]) {
        view.frame = CGRectMake(0, 0, 100, 88);
    }else{
        view.frame = CGRectMake(0, 0, 100, 64);
    }
    
    
    UIButton* btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
    btn1.backgroundColor = [UIColor blueColor];
    CGFloat width = view.frame.size.width;
    CGFloat height = view.frame.size.height;
    
    btn1.frame = CGRectMake(5, 5, 40, 40);
    
    //垂直居中
//    CGPoint point = btn1.center;
//    btn1.center = CGPointMake(point.x, view.center.y);
    
    //居中
  btn1.center =view.center;
    
    //水平居中
//    CGPoint point = btn1.center;
//    btn1.center = CGPointMake(view.center.x, point.y);

    [view addSubview:btn1];
//    NSLog(@"==%ld",[self isNotchScreen]);
    return view;
}


// iPhoneX、iPhoneXR、iPhoneXs、iPhoneXs Max等
// 判断刘海屏，返回YES表示是刘海屏
+ (BOOL)isNotchScreen {
    
    if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
        return NO;
    }
    
    CGSize size = [UIScreen mainScreen].bounds.size;
    NSInteger notchValue = size.width / size.height * 100;
    
    if (216 == notchValue || 46 == notchValue) {
        return YES;
    }
    
    return NO;
}


@end
